package com.guaju.yueshangLife.viewmodel.home;

import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.BindingAdapter;

import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.DefaultSliderView;
import com.guaju.yueshangLife.BR;
import com.guaju.yueshangLife.bean.Goods;
import com.guaju.yueshangLife.utils.ToastUtil;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;

/**
 * Created by guaju on 2018/9/28.
 */

public class RecommandVM extends BaseObservable {
    public ArrayList sliderList;
    public ArrayList<Goods> goodsList;

    @Bindable
    public ArrayList getSliderList() {
        return sliderList;
    }

    public void setSliderList(ArrayList sliderList) {
        this.sliderList = sliderList;
        notifyPropertyChanged(BR.sliderList);
    }

    @BindingAdapter("bind:addSlider")
    public static void addSlider(Banner banner, ArrayList sliderList) {
        if (sliderList != null && !sliderList.isEmpty()) {
//            for (final Object o : sliderList) {
//                DefaultSliderView sv = new DefaultSliderView(sliderLayout.getContext());
//                if (o instanceof Integer) {
//                    int oi = (int) o;
//                    sv.image(oi);
//                } else if (o instanceof String) {
//                    String os = (String) o;
//                    sv.image(os);
//                }
//                sv.setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() {
//                    @Override
//                    public void onSliderClick(BaseSliderView slider) {
//                        ToastUtil.show("slider clicked"+o.toString());
//                    }
//                });
//                sliderLayout.addSlider(sv);
            banner.setImages(sliderList);
            banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
            banner.setIndicatorGravity(BannerConfig.CENTER);
            banner.setDelayTime(5000);
            banner.start();
        }
    }
}



